/*
 * @(#)DropPartitionTask.java   1.0  2021年11月8日
 * 
 * Copyright (c)	2014-2020. All Rights Reserved.	GuangZhou hhmk Technology Company LTD.
 */
package com.swift.dts.task;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.swift.core.env.ConfigInterface;
import com.swift.dao.db.datasource.HandlerDataSource;
import com.swift.dts.dao.LogEventTableDao;
import com.swift.dts.loadconfig.model.DtsDataBase;

/**
 * 删除超时分区 
 * @author zhengjiajin
 * @version 1.0 2021年11月8日
 */
@Component
public class AutoPartitionTask {

    @Autowired
    private LogEventTableDao logEventTableDao;
    
    @Autowired
    private ConfigInterface<DtsDataBase> dataBaseConfigInterface;
    
    @Scheduled(cron="0 0 3 ? * *")
    public void doUpdate() {
        List<DtsDataBase> list = dataBaseConfigInterface.load();
        for(DtsDataBase db:list) {
            if(!db.getIsSource() && db.getIsRing()) {
                HandlerDataSource.putDataSource(db.getKey());
                logEventTableDao.addPartition();
                logEventTableDao.cleanPartition();
                HandlerDataSource.clear();
            }
        }
    }
}
